#define _CRT_SECURE_NO_WARNINGS 1

#include "ConcurrentAlloc.hpp"
#include "ObjectPool.hpp"

void Alloc1()
{
	for (int i = 0; i < 5; i++)
	{
		void* ptr = ConcurrentAlloc(7);
	}
}

void Alloc2()
{
	for (int i = 0; i < 6; i++)
	{
		void* ptr = ConcurrentAlloc(6);
	}
}

void TLSTest()
{
	std::thread t1(Alloc1);
	t1.join();

	std::thread t2(Alloc2);
	t2.join();
}

void TestConcurrentAlloc()
{
	void* p1 = ConcurrentAlloc(6);
	void* p2 = ConcurrentAlloc(4);
	void* p3 = ConcurrentAlloc(8);
	void* p4 = ConcurrentAlloc(1);
	void* p5 = ConcurrentAlloc(2);
	void* p6 = ConcurrentAlloc(3);

	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
	cout << p6 << endl;
	//for (int i = 0; i < 1024; i++)
	//{
	//	void* p1 = ConcurrentAlloc(6);
	//}
	//void* p2 = ConcurrentAlloc(6);
}

void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}

void MultiThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}

void TestMultiThread()
{
	std::thread t1(MultiThreadAlloc1);

	std::thread t2(MultiThreadAlloc2);

	t1.join();

	t2.join();
}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);

	void* p2 = ConcurrentAlloc(129 * 8 * 1024);
	ConcurrentFree(p2);
}

//int main()
//{
//	//TLSTest();
//	//TestObjectPool();
//	//TestConcurrentAlloc();
//	//TestMultiThread();
//	//BigAlloc();
//	return 0;
// }